You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
47 lines
1.4 KiB
47 lines
1.4 KiB
import { defineWrappedResponseHandler } from "#server/utils/handler";
|
|
import { R } from "#server/utils/response";
|
|
import { getCurrentUser } from "#server/utils/context";
|
|
import { getAgentBySlugAny, updateAgent, type UpdateAgentInput } from "#server/service/agent/agent";
|
|
|
|
export default defineWrappedResponseHandler(async (event) => {
|
|
const user = await getCurrentUser(event);
|
|
if (!user || user.role !== "admin") {
|
|
return R.error("仅管理员可更新 agent", null);
|
|
}
|
|
|
|
const agentSlug = getRouterParam(event, "agentSlug");
|
|
if (!agentSlug) {
|
|
return R.error("参数无效", null);
|
|
}
|
|
|
|
const existing = await getAgentBySlugAny(agentSlug);
|
|
if (!existing) {
|
|
return R.error("agent 不存在", null);
|
|
}
|
|
|
|
const body = await readBody(event);
|
|
const { slug, name, description, systemPrompt, defaultModelId, titleModelId, titleStrategy, enableThinking, enableTools, maxStepCount, isDefault, isCallable, sortOrder, enabled, toolIds } = body as UpdateAgentInput;
|
|
|
|
try {
|
|
const updated = await updateAgent(existing.id, {
|
|
slug,
|
|
name,
|
|
description,
|
|
systemPrompt,
|
|
defaultModelId,
|
|
titleModelId,
|
|
titleStrategy,
|
|
enableThinking,
|
|
enableTools,
|
|
maxStepCount,
|
|
isDefault,
|
|
isCallable,
|
|
sortOrder,
|
|
enabled,
|
|
toolIds,
|
|
});
|
|
return R.success(updated);
|
|
} catch (e) {
|
|
return R.error(e instanceof Error ? e.message : String(e), null);
|
|
}
|
|
});
|
|
|